package com.riant.day09;

/**
 * @Classname BankTes
 * @Description TODO
 * @Date 2021/3/30 16:09
 * @Created by 张斌
 */
public class BankTest {
    public static final int NACCOUNTS=100;
    public static final double INITIAL_BALANCE=1000;
    public static final double MAX_AMOUNT=1000;
    public static final int DELAY =10;

    public static void main(String[] args) {
        Bank bank=new Bank(NACCOUNTS,INITIAL_BALANCE);
        for(int i=0;i< NACCOUNTS;i++){
            int fromAccount=i;
            Runnable runnable=()->{
                try {
                    while (true){
                        int toAccount=(int)(bank.getSize()*Math.random());
                        double amount =MAX_AMOUNT*Math.random();
                        bank.tranfer(fromAccount,toAccount,amount);
                        Thread.sleep((int)(DELAY*Math.random()));
                    }
                }catch (InterruptedException e){

                }
            };
            Thread thread = new Thread(runnable);
            thread.start();
        }
    }
}
